*/
class ImportTest extends MediaWikiLangTestCase {
private function getDataSource( $xml ) {
return new ImportStringSource( $xml );
}
/**
* @covers WikiImporter
* @dataProvider getUnknownTagsXML
* @param string $xml
* @param string $text
* @param string $title
*/
public function testUnknownXMLTags( $xml, $text, $title ) {
$source = $this->getDataSource( $xml );
$importer = new WikiImporter(
$source,
MediaWikiServices::getInstance()->getMainConfig()
);
$importer->doImport();
$title = Title::newFromText( $title );
$this->assertTrue( $title->exists() );
$this->assertEquals( WikiPage::factory( $title )->getContent()->getNativeData(), $text );
}
public function getUnknownTagsXML() {
// @codingStandardsIgnoreStart Generic.Files.LineLength
return [
[
<<< EOF
TestImportPage
Should be ignored
0
14
15
Should be ignored
2016-01-03T11:18:43Z
Should be ignored
Admin
1
wikitext
text/x-wiki
noitazinagro tseb eht si ikiWaideM
phoiac9h4m842xq45sp7s6u21eteeq1
Should be ignored
Should be ignored
EOF
,
'noitazinagro tseb eht si ikiWaideM',
'TestImportPage'
]
];
// @codingStandardsIgnoreEnd
}
/**
* @covers WikiImporter::handlePage
* @dataProvider getRedirectXML
* @param string $xml
* @param string|null $redirectTitle
*/
public function testHandlePageContainsRedirect( $xml, $redirectTitle ) {
$source = $this->getDataSource( $xml );
$redirect = null;
$callback = function ( Title $title, ForeignTitle $foreignTitle, $revCount,
$sRevCount, $pageInfo ) use ( &$redirect ) {
if ( array_key_exists( 'redirect', $pageInfo ) ) {
$redirect = $pageInfo['redirect'];
}
};
$importer = new WikiImporter(
$source,
MediaWikiServices::getInstance()->getMainConfig()
);
$importer->setPageOutCallback( $callback );
$importer->doImport();
$this->assertEquals( $redirectTitle, $redirect );
}
public function getRedirectXML() {
// @codingStandardsIgnoreStart Generic.Files.LineLength
return [
[
<<< EOF
Test
0
21
20
2014-05-27T10:00:00Z
Admin
10
Admin moved page [[Test]] to [[Test22]]
wikitext
text/x-wiki
#REDIRECT [[Test22]]
tq456o9x3abm7r9ozi6km8yrbbc56o6
EOF
,
'Test22'
],
[
<<< EOF
Test
0
42
421
2014-05-27T11:00:00Z
Admin
10
Abcd
n7uomjq96szt60fy5w3x7ahf7q8m8rh
wikitext
text/x-wiki
EOF
,
null
],
];
// @codingStandardsIgnoreEnd
}
/**
* @covers WikiImporter::handleSiteInfo
* @dataProvider getSiteInfoXML
* @param string $xml
* @param array|null $namespaces
*/
public function testSiteInfoContainsNamespaces( $xml, $namespaces ) {
$source = $this->getDataSource( $xml );
$importNamespaces = null;
$callback = function ( array $siteinfo, $innerImporter ) use ( &$importNamespaces ) {
$importNamespaces = $siteinfo['_namespaces'];
};
$importer = new WikiImporter(
$source,
MediaWikiServices::getInstance()->getMainConfig()
);
$importer->setSiteInfoCallback( $callback );
$importer->doImport();
$this->assertEquals( $importNamespaces, $namespaces );
}
public function getSiteInfoXML() {
// @codingStandardsIgnoreStart Generic.Files.LineLength
return [
[
<<< EOF
Media
Special
Talk
User
User talk
Portal
Portal talk
EOF
,
[
'-2' => 'Media',
'-1' => 'Special',
'0' => '',
'1' => 'Talk',
'2' => 'User',
'3' => 'User talk',
'100' => 'Portal',
'101' => 'Portal talk',
]
],
];
// @codingStandardsIgnoreEnd
}
}